package task3.median;

import java.awt.image.renderable.ParameterBlock;
import java.security.InvalidParameterException;
import javax.media.jai.JAI;
import javax.media.jai.operator.MedianFilterDescriptor;
import task3.pimpmypipe.DataTransformationFilter;
import task3.util.FilterObservable;
import task3.util.ImageTO;

public class MedianFilter
  extends DataTransformationFilter<ImageTO>
{
  private int _kernelSize;
  private FilterObservable _observable;
  
  public MedianFilter()
    throws InvalidParameterException
  {
    this._kernelSize = 3;
    this._observable = new FilterObservable();
  }
  
  protected void process(ImageTO entity)
  {
    ParameterBlock parameters = new ParameterBlock();
    parameters.addSource(entity.getEditedImage());
    parameters.add(MedianFilterDescriptor.MEDIAN_MASK_SQUARE);
    parameters.add(3);
    
    entity.setEditedImage(JAI.create("medianfilter", parameters));
    
    this._observable.setChanged();
    this._observable.notifyObservers(entity);
  }
  
  public int getKernelSize()
  {
    return this._kernelSize;
  }
  
  public void setKernelSize(int kernelSize)
  {
    this._kernelSize = kernelSize;
  }
  
  public FilterObservable getObservable()
  {
    return this._observable;
  }
}
